package com.botann.projects.service;

import com.botann.projects.base.BaseService;
import com.botann.projects.base.BaseService;
import com.botann.projects.model.Dictionary;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * jiyi
 * DictionaryService
 * Created by 刘山国 on 2019/9/11.
 * Copyright (c) 2017 伯坦科技. All rights reserved
 */
@Service
public class DictionaryService extends BaseService implements DictionaryServiceIntf {
    @Override
    public Class loggerClass() {
        return DictionaryService.class;
    }


    @Override
    public List loadDictionaries(String mkey, String name) {
        return (List) loadDictionaries(null,null,mkey,name);
    }

    @Override
    public Object loadDictionaries(Integer pageIndex, Integer pageSize, String mkey, String name) {
        if (mkey != null && mkey.isEmpty()) mkey = null;
        if (name != null && name.isEmpty()) name = null;
        return sessionQuery(Dictionary.class,pageIndex,pageSize,"sort",conditions("mkey=","name like", "del="),mkey,like(name),0);
    }

    @Override
    public void saveOrUpdateDic(String json) {
        Dictionary dictionary = jsonToModel(json,Dictionary.class);
        sessionSaveOrUpdate(dictionary);
    }

    @Override
    public void deleteDics(String json) {
        List<Integer> ids = jsonToListModel(json,Integer.class);
        for (Integer id : ids) {
            sessionDelete(Dictionary.class,id);
        }
    }
}
